<?php
	require_once 'common.php';

	$common = new Common();
	list($user, $page) = call_user_func(array($common, 'index'));
	
	if(isset($_GET['act']) && $_GET['act'] == 'delete') {
		if (empty($_GET['id'])){
			echo '<script>';
			echo 'alert("参数有误");';
			echo '</script>';
			goto html;
		}
		call_user_func(array($common, 'delete'));
	}
html:
?>
<!DOCTYPE html>
<html>
	<head>
        <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
		<!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
		<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

		<!-- 可选的 Bootstrap 主题文件（一般不用引入） -->
		<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">

		<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
		<script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
	</head>
	<body>
	    <div class="container">
			<div><a href="add.php">添加用户</a></div>
			<div>
				<table class="table table-striped">
					<tr>
						<td>#</td>
						<td>账号</td>
						<td>昵称</td>
						<td>邮箱</td>
						<td>操作</td>
					</tr>
					<?php
						foreach($user as $document){
							?>
							<tr>
								<td><?php echo $document->_id ?></td>
								<td><?php echo $document->account ?></td>
								<td><?php echo $document->nickname ?></td>
								<td><?php echo $document->email ?></td>
								<td>
									<a href="">更新</a>
									<a href="javascript:if(confirm('确定删除吗?'))window.location.href='user.php?act=delete&id=<?php echo $document->_id;?>'">删除</a>
								</td>
							</tr>
							<?php
						}
					?>
				</table>
                <div style="float: right">
                    <?php
                        echo $page;
                    ?>
                </div>
			</div>
		</div>
	</body>
</html>